#!/bin/bash
# 该脚本只支持x86的机器运行
set -o errexit
set -o nounset
set -o pipefail

KIND_IMAGE="cis-hub-shanghai-1.cmecloud.cn/public/cka-kind:v1.28.0-001"
CLUSTER_NAME="cka-exam-env"

kind delete clusters $CLUSTER_NAME || true
kind create cluster --name $CLUSTER_NAME --config kind_cluster.yml --image $KIND_IMAGE

#TODO touch /opt/KUTR000402/KUTR00402.txt in node1

docker pull docker.m.daocloud.io/nginx
docker tag docker.m.daocloud.io/nginx nginx
docker pull docker.m.daocloud.io/redis
docker tag docker.m.daocloud.io/redis redis
docker pull docker.m.daocloud.io/busybox
docker tag docker.m.daocloud.io/busybox busybox

kind load -n "$CLUSTER_NAME" docker-image redis
kind load -n "$CLUSTER_NAME" docker-image nginx
kubectl label node cka-exam-env-worker2 disk=spinning

docker pull k8s.m.daocloud.io/metrics-server/metrics-server:v0.7.1
docker tag k8s.m.daocloud.io/metrics-server/metrics-server:v0.7.1 registry.k8s.io/metrics-server/metrics-server:v0.7.1
kind load -n "$CLUSTER_NAME" docker-image registry.k8s.io/metrics-server/metrics-server:v0.7.1

kubectl create ns app-team1
kubectl create ns foo

#准备第5题的环境
kubectl create ns corp-net

kubectl apply -f Q2_prepare.yml
kubectl apply -f Q6_prepare.yml
kubectl apply -f Q7_prepare.yml
kubectl apply -f Q8_prepare.yml
kubectl apply -f Q14_prepare.yml
kubectl apply -f Q15_prepare.yml

#第十三题环境
#TODO 需要找一个支持修改容量的csi插件，同时将sc的名字改成与题目一样，比较麻烦，后面研究补上

kubectl apply -f metrics-server.yml
kubectl apply -f Q16_prepare.yml

